package YunNotes.allnotes.token;

import YunNotes.allnotes.model.Notes;
import YunNotes.util.db.DBUtil;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;


public class TokenJudge {
    public int tokenJudge(String token) throws SQLException {
        //获得数据库的连接
        Connection conn = DBUtil.getConn();

        int userid = 0;

        String sql = "SELECT id FROM allnotes" +
                " where token=?";

        //执行sql语句方法
        PreparedStatement preparedStatement = conn.prepareStatement(sql);
        preparedStatement.setString(1, token);


        ResultSet rs = preparedStatement.executeQuery();
        Notes notes = new Notes();
        notes.setId(rs.getInt("id"));
        userid = notes.getId();


        preparedStatement.execute();
        return userid;
    }

}
